#ifndef thread_h__
#define thread_h__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

namespace gecko
{

//Sleep the calling thread.
void ThreadSleep(int milliseconds);

// Get the ID of the calling thread.
unsigned int GetThreadID();

// Get the index of the calling thread in the global thread ID table.
unsigned int GetThreadIndex();

// Register the thread with the global ID table.
void RegisterThread(unsigned int threadID);

// Remove the thread from the global ID table.
void UnRegisterThread(unsigned int threadID);

// Thread wrapper implementation.
class IThread
{
public:
	// default constructor
	IThread();

	// Destructor.
	virtual ~IThread();

	// Initialise the thread.
	void Initialise(const char * threadName);

	// is the thread running
	bool IsRunning();

protected:
	// Process function.  Override this to provide thread processing.
	virtual void Process() = 0;

private:
	// run the thread
	void Run();

	HANDLE m_threadHandle;
	unsigned long m_threadID;
	const char * m_threadName;
	bool m_threadRunning;

	friend void ThreadProc(void* param);
};

inline bool IThread::IsRunning()
{
	return m_threadRunning;
}

}

#endif
